<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-08-14 16:35:45
 * @LastEditTime: 2019-08-14 19:45:05
 * @LastEditors: Please set LastEditors
 -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box {
            margin: 100px auto;
            width: 300px;
            height: 300px;
        }

        form {}

        fieldset {
            /* display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: space-between; */
            text-align: center;
            width: 300px;
            height: 300px;
        }

        .box2 {
            text-align: center;
            margin-bottom: 30px;
            display: flex;
            justify-content: space-between;

        }



        input {
            width: 200px
        }
    </style>
</head>

<body>
    <div class="box">

        <form action="">
            <fieldset style="border-color: crimson">

                <legend>注册</legend>
                <h3>新用户注册</h3>
                <div class="box2">
                    <label for="name">用户名：</label>
                    <input type="text" id="name" placeholder="请输入用户">
                </div>
                <div class="box2">
                    <label for="password">密码：</label>
                    <input type="password" name="password" id="password" placeholder="密">
                </div>
                <div class="box2">
                    <label for="bgword">重复密码：</label><input type="password" name="password" id="bgword"
                        placeholder="密码">
                </div>
                <input type="button" value="注册" id="btn">
            </fieldset>

        </form>
    </div>
</body>
<script src="../common.js"></script>
<script>
    (function () {

        var name = document.getElementById('name'); //用户名
        var password = document.getElementById('password'); //密码1
        var bgword = document.getElementById('bgword'); //密码1.2
        var btn = document.getElementById('btn');
        let na = name.value.trim();
        let pasd = password.value.trim();
        name.onblur = () => {
            if (na) {
                ajax({
                    type: 'post',
                    url: 'api/breg.php',
                    data: {
                        name: na
                    },
                    success: str => {
                        if (str == 'yes') {

                            console.log('yes');

                        } else {
                            console.log('no');
                        }
                    }
                })
            }
        }
        btn.onclick = () => {
            ajax({
                type: 'post',
                url: 'api/reg.php',
                data: {
                    name: na,
                    password: pasd

                },
                success: str => {


                    console.log(str);
                }
            })
        }
    })();
</script>

</html>